package cn.ewan.cloud.tenant.data.router.service;

import cn.ewan.cloud.common.support.Log;
import cn.ewan.cloud.tenant.data.router.service.interceptor.HttpTenantInterceptor;
import cn.ewan.cloud.tenant.data.router.spring.TenantAutoConfiguration;
import cn.ewan.cloud.tenant.data.router.spring.build.BuildUtil;
import org.aspectj.lang.annotation.After;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lgh
 * @date 2022/12/26 11:21
 */
@Configuration
@ConditionalOnBean(TenantAutoConfiguration.class)
@AutoConfigureAfter(TenantAutoConfiguration.class)
public class TenantAutoServiceConfiguration implements InitializingBean {



    @Configuration
    static class TenantWebConfig implements WebMvcConfigurer {

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new HttpTenantInterceptor()).excludePathPatterns("/");
        }
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        String buildTime = new BuildUtil().logBuildTime();
        Log.NORMAL.info("===========tenant-service init finish=======, buildTime={}", buildTime);
    }
}
